//Table 5 final run

log using "$rootpath/log/Table_5_6_A12_A13.log", replace
use "$rootpath/processed_data/Estimation_HPV_Subset.dta", clear
gen epafe=year*100+epa_region
forval i=2/10 {
	gen region_trend`i'=0
	replace region_trend`i'=year if epa_region==`i'
	
}
gen obs_num=_n
sort epafe
egen test500=nvals(obs_num), by(epafe)
replace epafe=0 if test500<450
tabulate epafe, gen(epafe_)
reghdfe state_fine_rate treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster frsnumber)
summarize fine_rate if e(sample)==1
reghdfe fine_rate treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster frsnumber)
summarize fine_rate if e(sample)==1
reghdfe state_insp_rate treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster frsnumber)
summarize state_insp_rate if e(sample)==1
reghdfe insp_rate treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster frsnumber)
summarize insp_rate if e(sample)==1

did_multiplegt_dyn insp_rate frsnumber year treatXpost, normalize effects(1) placebo(0) cluster(frsnumber) trends_nonparam(naics)

did_multiplegt_dyn fine_rate frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(frsnumber) trends_nonparam(naics)

did_multiplegt_dyn state_insp_rate frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(frsnumber) trends_nonparam(naics)

did_multiplegt_dyn state_fine_rate frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(frsnumber) trends_nonparam(naics)


reghdfe fine_rate treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster state_number)
summarize fine_rate if e(sample)==1

reghdfe insp_rate treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster state_number)
summarize insp_rate if e(sample)==1

did_multiplegt_dyn insp_rate frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(state_number) trends_nonparam(naics)

did_multiplegt_dyn fine_rate frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(state_number) trends_nonparam(naics)


///FRV
use "$rootpath/processed_data/Estimation_FRV_Subset.dta", clear
gen epafe=year*100+epa_region
tabulate epafe, gen(epafe_)
reghdfe state_fine_rate22 treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster frsnumber)
summarize state_fine_rate22 if e(sample)==1
reghdfe fine_rate22 treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster frsnumber)
summarize fine_rate22 if e(sample)==1
reghdfe fine_rate22 treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster state_number)
summarize fine_rate22 if e(sample)==1
generate n3=floor(naics/1000)
generate n2=floor(naics/10000)

did_multiplegt_dyn state_fine_rate22 frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(frsnumber) trends_nonparam(n2)

did_multiplegt_dyn fine_rate22 frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(frsnumber) trends_nonparam(n2)

did_multiplegt_dyn fine_rate22 frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(state_number) trends_nonparam(n2)

reghdfe state_insp_rate22 treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster frsnumber)
summarize state_insp_rate22 if e(sample)==1
reghdfe insp_rate22 treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster frsnumber)
summarize insp_rate22 if e(sample)==1
reghdfe insp_rate22 treatXpost, absorb(frsnumber  epa_region#year naics#c.year) vce(cluster state_number)
summarize insp_rate22 if e(sample)==1

did_multiplegt_dyn state_insp_rate22 frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(frsnumber) trends_nonparam(n2)


did_multiplegt_dyn insp_rate22 frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(frsnumber) trends_nonparam(n2)


did_multiplegt_dyn insp_rate22 frsnumber year treatXpost, normalize   effects(1) placebo(0) cluster(state_number) trends_nonparam(n2)

log close
